package jvm.gc;

import java.util.ArrayList;
import java.util.List;

/*
* 测试stw（stop the world）行为
* */
public class Test3 {
    public static void main(String[] args) {
           new Thread(()->{
               List<String>rubbish=new ArrayList<>();
              while (true){
                  for (int i = 0; i <1000 ; i++) {
                      rubbish.add(i+"");
                  }
                  if(rubbish.size()>=10000){
                      rubbish.clear();
                      System.out.println("gc...");
                      System.gc();
                  }
              }
           },"gc").start();
        long begin = System.currentTimeMillis();
        new Thread(()->{
            while (true){
                long passTime=System.currentTimeMillis()-begin;
                System.out.println(passTime/1000+"."+(passTime%1000));
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"记时").start();
    }
}
